package org.git.movie.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.git.movie.entity.ProShop;
import org.git.movie.form.ProShopForm;
import org.git.movie.mapper.ext.ProShopExtMapper;
import org.git.movie.service.IProShopService;
import org.git.movie.vo.PageDto;
import org.git.movie.vo.ProShopVo;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * @author sqyc
 */
@Service
public class ProShopServiceImpl implements IProShopService {

    @Autowired
    private ProShopExtMapper proShopExtMapper;

    @Override
    public PageDto<ProShopVo> findProShopVoPage(ProShopForm proShopForm, int pageNo, int pageSize) {

        try{
            PageHelper.startPage(pageNo, pageSize, true);
            List<ProShop> list = proShopExtMapper.findAvailAbleProShopList(proShopForm);
            PageInfo page = new PageInfo(list);

            if(list.size() >= 1){
                List<ProShopVo> list2 = new ArrayList<>();
                for(ProShop item:list){
                    ProShopVo vo = new ProShopVo();
                    BeanUtils.copyProperties(item,vo);
                    list2.add(vo);
                }
                page.setList(list2);

            }
            return   PageDto.transPageInfo(page);
        }finally {
            PageHelper.clearPage();
        }

    }
}
